package com.xo.so.thuhien;

import java.util.HashMap;
import java.util.Map;

import android.app.Fragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xo.so.R;
import com.xo.so.jsouplocal.JsoupLocal;
import com.xo.so.model.KetQuaXoSoMienNam;

public class ItemListProvince extends Fragment {

	private static final Map<String, String> provinceUrls_1 = new HashMap<String, String>();
	static {
		provinceUrls_1.put("Tây Ninh",
				"http://xoso.wap.vn/ket-qua-xo-so-tay-ninh-xstn.html");
		provinceUrls_1.put("Đà Lạt",
				"http://xoso.wap.vn/ket-qua-xo-so-da-lat-xsdl.html");
		provinceUrls_1.put("Kiên Giang",
				"http://xoso.wap.vn/ket-qua-xo-so-kien-giang-xskg.html");
		provinceUrls_1.put("Cần Thơ",
				"http://xoso.wap.vn/ket-qua-xo-so-can-tho-xsct.html");
		provinceUrls_1.put("Vĩnh Long",
				"http://xoso.wap.vn/ket-qua-xo-so-vinh-long-xsvl.html");
		provinceUrls_1.put("Cà Mau",
				"http://xoso.wap.vn/ket-qua-xo-so-ca-mau-xscm.html");
		provinceUrls_1.put("Ti�?n Giang",
				"http://xoso.wap.vn/ket-qua-xo-so-tien-giang-xstg.html");
		provinceUrls_1.put("An Giang",
				"http://xoso.wap.vn/ket-qua-xo-so-an-giang-xsag.html");
		provinceUrls_1.put("Long An",
				"http://xoso.wap.vn/ket-qua-xo-so-long-an-xsla.html");
		provinceUrls_1.put("Vũng Tàu",
				"http://xoso.wap.vn/ket-qua-xo-so-vung-tau-xsvt.html");
		provinceUrls_1.put("Bình Thuận",
				"http://xoso.wap.vn/ket-qua-xo-so-binh-thuan-xsbt.html");
		provinceUrls_1.put("Hồ Chí Minh",
				"http://xoso.wap.vn/ket-qua-xo-so-ho-chi-minh-xshcm.html");
		provinceUrls_1.put("Bạc Liêu",
				"http://xoso.wap.vn/ket-qua-xo-so-bac-lieu-xsbl.html");
		provinceUrls_1.put("Bình Dương",
				"http://xoso.wap.vn/ket-qua-xo-so-binh-duong-xsbd.html");
		provinceUrls_1.put("Bến Tre",
				"http://xoso.wap.vn/ket-qua-xo-so-ben-tre-xsbtr.html");
		provinceUrls_1.put("Trà Vinh",
				"http://xoso.wap.vn/ket-qua-xo-so-tra-vinh-xsdtv.html");
		provinceUrls_1.put("Sóc Trăng",
				"http://xoso.wap.vn/ket-qua-xo-so-soc-trang-xsbst.html");
		provinceUrls_1.put("Đồng Tháp",
				"http://xoso.wap.vn/ket-qua-xo-so-dong-thap-xsdt.html");
		provinceUrls_1.put("Hậu Giang",
				"http://xoso.wap.vn/ket-qua-xo-so-hau-giang-xsdhg.html");
		provinceUrls_1.put("Bình Phước",
				"http://xoso.wap.vn/ket-qua-xo-so-binh-phuoc-xsbp.html");
		provinceUrls_1.put("Đồng Nai",
				"http://xoso.wap.vn/ket-qua-xo-so-dong-nai-xsdn.html");
	}
	private View rootView;
	private TextView titleText;
	private TextView giaiTamSo1;
	private TextView giaiBaySo1;
	private TextView giaiSauSo1;
	private TextView giaiSauSo2;
	private TextView giaiSauSo3;
	private TextView giaiNamSo1;
	private TextView giaiTuSo1;
	private TextView giaiTuSo2;
	private TextView giaiTuSo3;
	private TextView giaiTuSo4;
	private TextView giaiTuSo5;
	private TextView giaiTuSo6;
	private TextView giaiTuSo7;
	private TextView giaiBaSo1;
	private TextView giaiBaSo2;
	private TextView giaiNhiSo1;
	private TextView giaiNhatSo1;
	private TextView giaiDBSo1;

	private TextView duoiSo0;
	private TextView duoiSo1;
	private TextView duoiSo2;
	private TextView duoiSo3;
	private TextView duoiSo4;
	private TextView duoiSo5;
	private TextView duoiSo6;
	private TextView duoiSo7;
	private TextView duoiSo8;
	private TextView duoiSo9;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.data_mien_nam, container, false);

		return rootView;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		titleText = (TextView) view
				.findViewById(R.id.text_title_truyen_thong_tinh);
		giaiTamSo1 = (TextView) view.findViewById(R.id.number_giai_tam);
		giaiBaySo1 = (TextView) view.findViewById(R.id.number_giai_bay);
		giaiSauSo1 = (TextView) view.findViewById(R.id.number_giai_sau_1);
		giaiSauSo2 = (TextView) view.findViewById(R.id.number_giai_sau_2);
		giaiSauSo3 = (TextView) view.findViewById(R.id.number_giai_sau_3);
		giaiNamSo1 = (TextView) view.findViewById(R.id.number_giai_nam);
		giaiTuSo1 = (TextView) view.findViewById(R.id.number_giai_tu_1);
		giaiTuSo2 = (TextView) view.findViewById(R.id.number_giai_tu_2);
		giaiTuSo3 = (TextView) view.findViewById(R.id.number_giai_tu_3);
		giaiTuSo4 = (TextView) view.findViewById(R.id.number_giai_tu_4);
		giaiTuSo5 = (TextView) view.findViewById(R.id.number_giai_tu_5);
		giaiTuSo6 = (TextView) view.findViewById(R.id.number_giai_tu_6);
		giaiTuSo7 = (TextView) view.findViewById(R.id.number_giai_tu_7);
		giaiBaSo1 = (TextView) view.findViewById(R.id.number_giai_ba_1);
		giaiBaSo2 = (TextView) view.findViewById(R.id.number_giai_ba_2);
		giaiNhiSo1 = (TextView) view.findViewById(R.id.number_giai_nhi);
		giaiNhatSo1 = (TextView) view.findViewById(R.id.number_giai_nhat);
		giaiDBSo1 = (TextView) view.findViewById(R.id.number_giai_dac_biet);
		duoiSo0 = (TextView) view.findViewById(R.id.number_loto_number_0);
		duoiSo1 = (TextView) view.findViewById(R.id.number_loto_number_1);
		duoiSo2 = (TextView) view.findViewById(R.id.number_loto_number_2);
		duoiSo3 = (TextView) view.findViewById(R.id.number_loto_number_3);
		duoiSo4 = (TextView) view.findViewById(R.id.number_loto_number_4);
		duoiSo5 = (TextView) view.findViewById(R.id.number_loto_number_5);
		duoiSo6 = (TextView) view.findViewById(R.id.number_loto_number_6);
		duoiSo7 = (TextView) view.findViewById(R.id.number_loto_number_7);
		duoiSo8 = (TextView) view.findViewById(R.id.number_loto_number_8);
		duoiSo9 = (TextView) view.findViewById(R.id.number_loto_number_9);
		Bundle b = getArguments();

		String idTinh_1 = b.getString(FragmentMienNam.TINH_ID);
		KQXSMNLoader kQXSMNLoader = new KQXSMNLoader();
		kQXSMNLoader.execute(idTinh_1);
		
//		String idTinh = b.getString(FragmentMienTrung.TINH_ID);
//		KQXSMTLoader kQXSMTLoader = new KQXSMTLoader();
//		kQXSMTLoader.execute(idTinh);

		super.onViewCreated(view, savedInstanceState);
	}

	

	private class KQXSMNLoader extends
			AsyncTask<String, Void, KetQuaXoSoMienNam> {

		@Override
		protected KetQuaXoSoMienNam doInBackground(String... params) {

			return JsoupLocal.parseKQXSMN(provinceUrls_1.get(params[0]));
		}

		@Override
		protected void onPostExecute(KetQuaXoSoMienNam result) {
			if (result != null) {
				titleText.setText(result.getTitle());

				giaiTamSo1.setText(result.getMaSoTrungThuong(0)[0]);
				giaiBaySo1.setText(result.getMaSoTrungThuong(1)[0]);
				giaiSauSo1.setText(result.getMaSoTrungThuong(2)[0]);
				giaiSauSo2.setText(result.getMaSoTrungThuong(2)[1]);
				giaiSauSo3.setText(result.getMaSoTrungThuong(2)[2]);
				giaiNamSo1.setText(result.getMaSoTrungThuong(3)[0]);
				giaiTuSo1.setText(result.getMaSoTrungThuong(4)[0]);
				giaiTuSo2.setText(result.getMaSoTrungThuong(4)[1]);
				giaiTuSo3.setText(result.getMaSoTrungThuong(4)[2]);
				giaiTuSo4.setText(result.getMaSoTrungThuong(4)[3]);
				giaiTuSo5.setText(result.getMaSoTrungThuong(4)[4]);
				giaiTuSo6.setText(result.getMaSoTrungThuong(4)[5]);
				giaiTuSo7.setText(result.getMaSoTrungThuong(4)[6]);
				giaiBaSo1.setText(result.getMaSoTrungThuong(5)[0]);
				giaiBaSo2.setText(result.getMaSoTrungThuong(5)[1]);
				giaiNhiSo1.setText(result.getMaSoTrungThuong(6)[0]);
				giaiNhatSo1.setText(result.getMaSoTrungThuong(7)[0]);
				giaiDBSo1.setText(result.getMaSoTrungThuong(8)[0]);

				duoiSo0.setText(result.getCacSoDauDuoiMaGiai(0));
				duoiSo1.setText(result.getCacSoDauDuoiMaGiai(1));
				duoiSo2.setText(result.getCacSoDauDuoiMaGiai(2));
				duoiSo3.setText(result.getCacSoDauDuoiMaGiai(3));
				duoiSo4.setText(result.getCacSoDauDuoiMaGiai(4));
				duoiSo5.setText(result.getCacSoDauDuoiMaGiai(5));
				duoiSo6.setText(result.getCacSoDauDuoiMaGiai(6));
				duoiSo7.setText(result.getCacSoDauDuoiMaGiai(7));
				duoiSo8.setText(result.getCacSoDauDuoiMaGiai(8));
				duoiSo9.setText(result.getCacSoDauDuoiMaGiai(9));

			}
			super.onPostExecute(result);
		}
	}
}
